﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;

namespace VTV.TaskManagementSystem.Common
{
    public static class MD5Helper
    {
        public static string ToMD5(this string stringInput)
        {
            try
            {
                var md5Object = new MD5CryptoServiceProvider();

                byte[] byteHash = md5Object.ComputeHash(Encoding.UTF8.GetBytes(stringInput.Trim()));

                var result = new StringBuilder();

                foreach (var b in byteHash)
                {
                    result.Append(String.Format("{0:x2}", b));
                }

                return result.ToString();
            }
            catch
            {
                return null;
            }
        }
    }
}
